import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
      title: 'Flutter name route ',
      theme: ThemeData(primarySwatch: Colors.blue),
      routes: {
        "new_page": (context) => NewRoute(),
        "/": (context) => HomePage() // 注册首页路由
      },
      home: HomePage(),
    ));

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('name route demo'),
      ),
      body: Center(
        child: ElevatedButton(
          onPressed: () async {
            var result = await Navigator.pushNamed(context, "new_page",
                arguments: {'上个页面参数'});
            print(result);
          },
          child: const Text('name route demo'),
        ),
      ),
    );
  }
}

class NewRoute extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    Set<String> args = ModalRoute.of(context)?.settings.arguments as Set<String>;
    String param = args.first;

    return Scaffold(
      appBar: AppBar(
        title: const Text('new route'),
      ),
      body: Center(
        child: Column(
          children: [
            Text(param),
            TextButton(onPressed: () => {
              Navigator.pop(context, '返回页面你参数')
            }, child: const Text('返回'))
          ],
        )
      ),
    );
  }
}
